package com.yequan.designpattern.proxy.third_generation;

public class GamePlayer implements IGamePlayer2 {

    private String username;
    private IGamePlayer2 gameProxy = null;

    public GamePlayer(String username) {
        this.username = username;
    }

    @Override
    public IGamePlayer2 getProxy() {
        gameProxy = new GamePlayerProxy(this);
        return gameProxy;
    }

    @Override
    public void login(String account, String password) {
        if (isProxy()) {
            System.out.println("用户:" + username + "登录了" + account + "账号进行游戏");
        } else {
            System.out.println("请使用指定代理访问");
        }
    }

    @Override
    public void killBoss() {
        if (isProxy()) {
            System.out.println("用户" + username + "在打怪");
        } else {
            System.out.println("请使用指定代理访问");
        }
    }

    @Override
    public void upgrade() {
        if (isProxy()) {
            System.out.println("用户" + username + "升级了");
        } else {
            System.out.println("请使用指定代理访问");
        }
    }

    private boolean isProxy() {
        return gameProxy != null;
    }
}
